package com.atguigu.gmall.list.api;

import com.atguigu.gmall.common.result.Result;
import com.atguigu.gmall.list.model.SearchParam;
import com.atguigu.gmall.list.model.SearchResponseVo;
import com.atguigu.gmall.list.service.SearchService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;

/**
 * @author: atguigu
 * @create: 2023-03-03 14:07
 */
@RestController
@RequestMapping("/api/list")
public class ListApiController {


    @Autowired
    private SearchService searchService;

    /**
     * 提供给详情服务调用:更新商品热度分值
     * @param skuId
     */
    @GetMapping("/inner/incrHotScore/{skuId}")
    public void incrHotScore(@PathVariable("skuId") Long skuId){
        searchService.incrHotScore(skuId);
    }



    /**
     * 商品检索
     *  业务数据检索
     *  过滤项条件聚合
     *
     * @param searchParam
     * @return
     */
    @PostMapping({"/inner", ""})
    public Result search(@RequestBody SearchParam searchParam, HttpServletRequest request) {
        String userId = request.getHeader("userId");
        System.out.println("用户ID:"+userId);
        SearchResponseVo responseVo = searchService.search(searchParam);
        return Result.ok(responseVo);
    }
}
